import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';
enum Api {
  page = '/demo/demo/page',
  save = '/demo/demo/add',
  edit = '/demo/demo/edit',
  get = '/demo/demo/queryById',
  delete = '/demo/demo/delete',
  importExcel = '/demo/demo/import/demo',
  exportXls = '/demo/demo/export-excel/demo',
  deleteBatch = '/demo/demo/deleteBatch',
  switchStatus = '/demo/demo/switch-status',
}
/**
 * 导出api
 */
export const getExportUrl = Api.exportXls;

export const getImportUrl = Api.importExcel;


/**
 * 查询列表
 * @param params
 */
export const getPage = (params?) => {
  return defHttp.get({ url: Api.page, params });
};

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};

/**
 * 查询详情
 * @param params
 */
export const getById = (params) => {
  return defHttp.get({ url: Api.get, params });
};

/**
 * 单条删除
 * @param params
 */
export const deleteById = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

/**
 * 自定义上传
 * @param customUpload
 */
export const customUpload = (params) => {
  defHttp.uploadFile({ url: Api.importExcel }, params);
};


//切换状态
export function switchStatus(data) {
  return defHttp.post({ url: Api.switchStatus,data})
}



